<template>

	<view class="layout">
		<view class="fui-page__wrap" :style="{paddingBottom:height+'px'}">
			<Index v-if="current===0"></Index>
			<Message v-if="current===1"></Message>
			<ServiceDesk v-if="current ===3"></ServiceDesk>
			<My v-if="current ===4 "></My>
		</view>
		<fui-tabbar selectedColor="#0052D9" :tabBar="tabBar" :current="current" @init="init"
			@click="itemClick"></fui-tabbar>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';

	import ServiceDesk from './subPages/serviceDesk/index.vue'
	import My from './subPages/my/index.vue'
	import Index from './subPages/index/index.vue'
	import Message from './subPages/message/index.vue'
	import {
		useWx
	} from '../../store/modules/wx';
	import {
		mapActions
	} from 'pinia'
	export default {

		components: {
			ServiceDesk,
			My,
			Index,
			Message
		},
		data() {
			return {
				current: 0,
				tabBar: [{
						text: "首页",
						iconName: 'home',
						selectedIconName: "home-fill"
					},
					{
						text: "消息",
						iconName: 'message',
						selectedIconName: "message-fill"
					},
					{
						text: "扫一扫",
						iconPath: '/static/images/scan.jpg',
						midButton: true,
						width: 92,
						height: 92,
						bottom: 40
					},
					{
						text: "工作台",
						iconName: 'classify',
						selectedIconName: "classify-fill"
					},
					{
						text: "我的",
						iconName: 'my',

						selectedIconName: "my-fill"
					}
				]
			}
		},
		onLoad() {
			console.log('onLoad');
		},
		onShow() {
			console.log('onShow');
		},
		created() {
			console.log('起那命------');
		},
		methods: {
			...mapActions(useWx, ['scanCode', 'injectSdk']),

			itemClick(e) {
				console.log(e, 'eee');
				if (e.index === 2) {
					this.injectSdk(() => {

						this.scanCode((res) => {
							window.location.href = res
						})
					})
					// wx_scanCode()
				} else {
					this.current = e.index
					uni.setNavigationBarTitle({
						title: ['首页', '消息', '', '工作台', '我的'][e.index]
					})
				}
			},
			init(e) {
				//处理tabbar高度，避免内容被tabbar遮住
				this.height = e.height
			},
		}
	}
</script>

<style scoped lang="scss">
	.layout {
		height: 100vh;
		width: 100%;
		// z-index: 0;
		background-image: url('/assets/images/background.png');
		background-repeat: no-repeat;
		background-size: 100%;

		&-img {
			z-index: 0;
			width: 100%;
			position: absolute;
			height: 100%;
		}
	}

	.fui-page__wrap {
		padding: 0 32rpx;
		padding-top: 32rpx;
	}
</style>